<!DOCTYPE html>
<html>

<head>
    <title>理财</title>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0,maximum-scale=1,user-scalable=no">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="telephone=no" name="format-detection">
    <link rel="stylesheet" type="text/css" href="/resource/web/css/reset.css">
    <link rel="stylesheet" type="text/css" href="/resource/web/css/finacing-gofinal.css">
    <script type="text/javascript" src="/resource/web/js/flexible.js"></script>
    <script type="text/javascript" src="/resource/web/js/jquery-1.11.1.min.js"></script>
</head>

<body>
    <div class="title">
        <p>{{$title}}</p>
        <a href="/Web/ft/{{$auto_id}}.html"><img class="back" src="/resource/web/img/newhead/path_7_copy.png"></a>
        <a href="#0"></a>
    </div>
    <div class="my-balance">
        <p class="myb-tit">剩余可投金额(元)</p>
        <p class="myb-num"></p>
    </div>
    <div class="set-money">
        <input id="setm-ipt" type="" name="" placeholder="账户余额">
        <p class="stm-tit">投资金额</p>
        <img class="my-cl" src="/resource/web/img/finacing/my_close.png">
        <p class="set-sy">预计收益<span class="set-num">0.00元</span></p>
    </div>
    <div class="use-red">
        <p class="ur-l">可用红包</p>
        <p class="ur-r ur-have">无可用红包</p>
        <p class="ur-r ur-dis" style="display: none;"></p>
        <p id="award" style="display: none;">0</p>
    </div>
    <div class="use-red use-red2">
        <p class="ur-l">可用加息券</p>
        <p class="ur-r ur-tick">加息<span>2</span>％{{--<img class="to-r" src="/resource/web/img/finacing/go_r3.png">--}}</p>
        <p id="ticket" style="display: none;"></p>
    </div>
    <div class="agree">
        <p><span onClick="location.href='/Web/invest_agreement.html'">同意《投资协议书》</span>理财有风险，投资需谨慎</p>
        <div class="fina-btn">立即加入</div>
    </div>
    <!-- 弹窗 -->
    <div class="mod-tanchu" style="display: none;">
        <!-- 余额不足 -->
        <div class="mt-cont" style="display: none;">
            <p class="">账户余额不足，请充值****元</p>
            <ul class="mt-btn tcf-flex tcf-justify-center">
                <li><p class="no-btn">取消</p></li>
                <li><a href="#0"><p class="yes-btn">确定</p></a></li>
            </ul>
        </div>
    </div>
    <input id="autoid" style="display: none;" value="{{$auto_id}}">
    <input id="rate" style="display: none;" value="{{$rate}}">
<script type="text/javascript">
    $(".my-cl").click(function(){
        $("#setm-ipt").val("");
    });

    $(".no-btn").click(function() {
        $(".mod-tanchu").css("display","none");
        $(".mod-tanchu").css("display","none");
    });

    var auto_ids = $("#autoid").val();
    var rate = $("#rate").val();
    var award = $("#award").html();
    var ticket = $("#ticket").val();

    $(document).ready(function(){
        $.ajax({
            type: 'GET',
            processData: false,
            url: '/Web/financing_display?item_id='+auto_ids,
            dataType: 'json',
            success: function(data){
                console.log(data.data);
                var arrLen = data.data.length;
                var arrlist = data.data;
                $("#setm-ipt").on("keyup",function(){
                    var setms = $(this).val();
                    var sj = Math.round((((setms*data.data.rate_loaner)/100)*data.data.deadline/365)*100)/100;
                    $(".set-num").html(sj+"元");
                    var len = data.data.award;
                    for ( t in len){
                        //console.log(len[t].restrict_amount);
                        if (setms>=1000 && setms<5000 && len[t].restrict_amount == 1000){
                            $(".ur-have").css("display","none");
                            $(".ur-dis").css("display","block");
                            award = len[t].auto_id;
                            rate = data.data.rate_loaner;
                            $(".ur-dis").html("<img class='ur-red' src='/resource/web/img/finacing/touzi_red.png'>满"+len[t].restrict_amount+"送"+len[t].amount+"元");
                        }
                        if(setms>=5000 && setms<10000 && len[t].restrict_amount == 5000){
                            $(".ur-have").css("display","none");
                            $(".ur-dis").css("display","block");
                            award = len[t].auto_id;
                            rate = data.data.rate_loaner;
                            $(".ur-dis").html("<img class='ur-red' src='/resource/web/img/finacing/touzi_red.png'>满"+len[t].restrict_amount+"送"+len[t].amount+"元");
                        }
                        if (setms>=10000 && setms<30000 && len[t].restrict_amount == 10000) {
                            $(".ur-have").css("display","none");
                            $(".ur-dis").css("display","block");
                            award = len[t].auto_id;
                            rate = data.data.rate_loaner;
                            $(".ur-dis").html("<img class='ur-red' src='/resource/web/img/finacing/touzi_red.png'>满"+len[t].restrict_amount+"送"+len[t].amount+"元");
                        } if (setms>=30000 && setms<50000 && len[t].restrict_amount == 30000){

                            $(".ur-dis").html("<img class='ur-red' src='/resource/web/img/finacing/touzi_red.png'>满"+len[t].restrict_amount+"送"+len[t].amount+"元");
                        } if(setms>=50000 && len[t].restrict_amount == 50000){
                            $(".ur-have").css("display","none");
                            $(".ur-dis").css("display","block");
                            award = len[t].auto_id;
                            rate = data.data.rate_loaner;
                            $(".ur-dis").html("<img class='ur-red' src='/resource/web/img/finacing/touzi_red.png'>满"+len[t].restrict_amount+"送"+len[t].amount+"元");
                        }if (setms<1000) {
                            $("#award").html("0");
                            $(".ur-have").css("display","block");
                            $(".ur-dis").css("display","none");
                        }
                    }
                });
                if (data.data.ticket.length > 0){
                    $(".ur-tick").html("<img class='ur-red' src='/resource/web/img/finacing/touzi_tick.png'>"+data.data.ticket[0].rate+"%");
                    $("#ticket").html(data.data.ticket[0].auto_id);
                }else {
                    $("#ticket").html("0");
                    $(".ur-tick").html("暂无加息券");
                }
                $("#setm-ipt").attr("placeholder","账户余额 "+data.data.account+"元");
                $(".myb-num").html(data.data.balance_amount);
            },
            error: function(xhr, type){
                console.log('Ajax error!');
            }
        });
    });
    $("#setm-ipt").on("change",function(){
        console.log("利"+rate);

    });
    var rates = rate;
    $(".fina-btn").click(function(){
        var item_id = auto_ids;
        var ratee = rates;
        var amount = $("#setm-ipt").val();
        var ticket = $('#ticket').html();
        if( amount == "" ){
            alert("请输入投资金额");
            return false;
        }else if (!/^[0-9]*$/.test(amount)) {
            alert("投资金额必须是数字");
            return false;
        }
        else if ( amount%100!==0 ) {
            alert("请输入100的整数倍");
            return false;
        }
        else {
            $.ajax({
                url: '/Web/confirm_invest',
                type : "POST",
                data: {item_id:item_id,rate:ratee,amount:amount,award_id:award,ticket_id:ticket},
                dataType : "json",
                cache:"false",
                timeout:30000,
                success : function(json) {
                    if(json.code == 1000){
                        location="/Web/invest_success.html?amount="+json.data;
                    }else{
                        alert(json.msg);
                    }

                }

            });
        }

    })
</script>
</body>

</html>
